import flash.utils.Dictionary;
import mx.collections.ArrayCollection;
import mx.formatters.DateFormatter;
import utils.loadingBox;
private var electricid:String;
public static var MONTH:String       = 'month';
public static var DAYS:String        = 'days';
public static var YEAR:String        = 'year';
public static var MONTHS:String      = 'months';
public static var DAY:String         = 'day';
public static var HOURS:String       = 'hours';
public static var MINUTES:String     = 'minutes';
private static const digit:int       = 2;
private static const digitEquip:int  = 3;
private static var Empty:String      = '';
[Bindable]
private var acSelector:ArrayCollection;
[Bindable]
private var strTimeRange:String      = Empty;
[Bindable]
private var usagePrevious:Number;
[Bindable]
private var usageCurrent:Number;
[Bindable]
private var usageVariation:Number;
[Bindable]
private var lblPrevious:String;
[Bindable]
private var lblCurrent:String;
[Bindable]
private var lblVariation:String;
[Bindable]
private var strCO2:String            = Empty;
[Bindable]
private var strTREE:String           = Empty;
[Bindable]
private var strGAS:String            = Empty;
[Bindable]
private var strRank:String           = Empty;
[Bindable]
private var strTotal:String          = Empty;
private var sDate:Date;
private var dict:Dictionary;
private static var startError:String = "起始時間設定錯誤!!";
private var loading:loadingBox;

private static function addWeeks(date:Date, weeks:Number):Date
{
	return addDays(date, weeks * 7);
}

private static function addDays(date:Date, days:Number):Date
{
	return addHours(date, days * 24);
}

private static function addHours(date:Date, hours:Number):Date
{
	return addMinutes(date, hours * 60);
}

private static function addMinutes(date:Date, mins:Number):Date
{
	return addSeconds(date, mins * 60);
}

private static function addSeconds(date:Date, secs:Number):Date
{
	var ns:Number  = secs * 1000;
	var sum:Number = date.getTime() + ns;
	return new Date(sum);
}

private static function getTime(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	if (date.hours == 0)
	{
		df.formatString = "00:NN:SS";
	}
	else
	{
		df.formatString = "HH:NN:SS";
	}
	result = df.format(date);
	return result;
}

private static function getDate(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	df.formatString = "YYYY-MM-DD";
	result = df.format(date);
	return result;
}

private static function getFullDate(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	if (date.hours == 0)
	{
		df.formatString = "YYYY-MM-DD 00:NN:SS";
	}
	else
	{
		df.formatString = "YYYY-MM-DD HH:NN:SS";
	}
	result = df.format(date);
	return result;
}

private static function getYearMonth(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	df.formatString = "YYYY-MM";
	result = df.format(date);
	return result;
}

private static function getMonthDay(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	df.formatString = "MM-DD";
	result = df.format(date);
	return result;
}

private static function getHourMinute(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	if (date.hours == 0)
	{
		df.formatString = "00:NN";
	}
	else
	{
		df.formatString = "HH:NN";
	}
	result = df.format(date);
	return result;
}

private static function getYearMonthC(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	df.formatString = "YYYY年MM月";
	result = df.format(date);
	return result;
}

private static function getYearMonthDayC(date:Date):String
{
	var result:String;
	var df:DateFormatter = new DateFormatter();
	df.formatString = "YYYY年MM月DD日";
	result = df.format(date);
	return result;
}
